package com.kdtech.analyse.video;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import com.kdtech.crawler.CrawlHTML;
import com.kdtech.crawler.at.UrlArgumentTop;
import com.kdtech.entity.crawler.UrlMeta;
import com.kdtech.entity.data.NewsMeta;
import com.kdtech.utils.DateUtils;
import com.kdtech.utils.NumberUtils;
import com.kdtech.utils.StringUtils;
import com.kdtech.analyse.AnalyseNews;

public class IqiyiVideoAnalyse implements AnalyseNews {



	
	public boolean isDetailPage(String url) {
		boolean bRet = false;
//		if(url.indexOf("ad") != -1 || url.indexOf("public") != -1 || url.indexOf("hosts") != -1) {
//			return bRet;
//		}
		String[] regex = {
				"http://www.iqiyi.com/v_[a-z0-9]+.html",
				};
		for (int i = 0; i < regex.length; i++) {
			if (url.matches(regex[i])) {
				return true;
			}
		}
		return bRet;
	}	

	
	public NewsMeta parserHtml(UrlMeta urlMeta) {

		String url = urlMeta.getUrl(); 

		String html = urlMeta.getHtml();

		/*
		 * 定义新闻实体需要的字段
		 */
		String title = null;
		String dateStr = null;
		String author = null;
		String desc = null;
		Long dateLong = null;
		String commentNum = null;
		String clickNum = null;
		

		Document doc = Jsoup.parse(html);
		
		title = doc.select("#widget-videotitle").text();// 标题
		if(title.startsWith("：")){
			title = title.substring("：".length());
		}
		dateStr = doc.select("#widget-vshort-ptime").text();
		dateLong = DateUtils.matchDate(dateStr);// 时间
		if(dateLong==null){
			dateLong = DateUtils.matchDate(doc.select("meta[name=title]").attr("content"));// 时间
		}
		
	
		desc = doc.select("p#widget-vshort-morewrap").attr("daat-init-moredesc"); //描述
		if(StringUtils.isBlank(desc))
		desc = doc.select("p#widget-vshort-lesswrap").attr("daat-init-moredesc"); //描述
		
		
		NewsMeta meta = new NewsMeta();
		meta.setTitle(title);
		meta.setContent(desc);
		meta.setAuthor(author);
		meta.setUrl(url);
		meta.setClickNum(NumberUtils.parseInt(clickNum));
		meta.setCommentNum(NumberUtils.parseInt(commentNum));
		meta.setDate(dateLong);
		return meta;
	}
	

	
	public NewsMeta Update(NewsMeta meta) {
		
		return null;
	}


	

}
